/**
 * @description priceModel Service
 */

 const { priceModel } = require('../db/index')
 const Op = require('sequelize').Op

 
 /**
  * 修改用户信息
  * @param {*} param0 要修改的用户信息
  * @param {*} param1 查询条件
  */
 async function updateData(
   params,
   id
 ) {
   // 拼接修改内容
   const updateObj = params
 
   // 拼接查询条件
   const whereOption = {}
   if (id) {
     whereOption.id = id
   }
 
   // 执行修改
   const result = await priceModel.update(updateObj, {
     where: whereOption
   })
   return result[0] > 0
 }
 
 
 /**
  * 分页查询所有用户
  * @param {number} page 当前页码
  * @param {number} pageSize 每页条数
  */
 async function queryAll({ page = 1, pageSize = 10 }) {
   if (page < 1) {
     page = 1
   }
   const result = await priceModel.findAll({
     limit: pageSize,
     offset: (page - 1) * pageSize,
   })
   const total = await priceModel.findAll()
   console.log(total.length)
   return {
     page,
     pageSize,
     total: total.length,
     data: result
   }
 }
 
 module.exports = {
   updateData,
   queryAll,
 }
 